//
//  HttpRequest.h
//  RedGrass
//
//  Created by wukong on 2018/12/29.
//  Copyright © 2018年 hongcaosp. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "HABaseSessionManager.h"


typedef void (^SuccessBlock)(id data);
typedef void (^FailBlock)(NSInteger code,NSString *message);
typedef id (^ParseBlock)(id data);
typedef void(^ExceptionHandler)(NSInteger code,NSString *message);
typedef void (^ProgressBlock)(id data);

@protocol Response <NSObject>

-(id)getResult;
-(BOOL)isBusinessOk;
-(NSInteger)getBuinessCode;
-(NSString *)getBusinessMsg;

@end


NS_ASSUME_NONNULL_BEGIN

@interface HttpRequest : NSObject

+(void)setExceptionHandler:(ExceptionHandler)eh;
+(NSString *)host;
+(HttpRequest *)buildRequest:(NSString *)path;
+(HttpRequest *)buildRequest:(NSString *)path withHeader:(NSDictionary *)headers;

-(void)post:(NSDictionary *)params success:(SuccessBlock)sb fail:(FailBlock)fb parse:(ParseBlock)pb;
-(void)get:(NSDictionary *)params success:(SuccessBlock)sb fail:(FailBlock)fb;
-(void)post:(NSDictionary *)params success:(SuccessBlock)sb fail:(FailBlock)fb;

//上传图片
-(void) uploadImageWithData:(NSData *)data imgName:(NSString *)imageName params:(NSDictionary *)params success:(SuccessBlock)sb fail:(FailBlock)fb;

//下载
-(void)downloadWithUrl:(NSString *)url progressBlock:(ProgressBlock)progressBlock successBlock:(SuccessBlock)successBlock failBlock:(FailBlock)failBlock;


@end

NS_ASSUME_NONNULL_END
